Improved error logging on upgrade failure.
authorrobertl <robertl>
Mon, 12 Apr 2010 02:53:03 +0000 (02:53 +0000)
committerrobertl <robertl>
Mon, 12 Apr 2010 02:53:03 +0000 (02:53 +0000)
gui/babeldata.h
gui/mainwindow.cpp
gui/upgrade.cpp
gui/upgrade.h

index 2bf8c6eb8c130e4adeb132fc7710cf7ca587203b..c0b44cec1ad47581eee8911f2b1f19cb54025b90 100644 (file)
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-// $Id: babeldata.h,v 1.6 2010/04/11 18:11:46 robertl Exp $
+// $Id: babeldata.h,v 1.7 2010/04/12 02:53:04 robertl Exp $
 //------------------------------------------------------------------------
 //
 //  Copyright (C) 2009  S. Khai Mong <khai@mangrai.com>.
@@ -57,6 +57,10 @@ public:
     upgradeCheckMethod(0),
     upgradeCheckTime(QDateTime(QDate(2001, 1, 1), QTime(0, 0))),
     installationUuid(QUuid::createUuid().toString()),
+    upgradeCallbacks(0),
+    upgradeDeclines(0),
+    upgradeErrors(0),
+    upgradeOffers(0),
     startupVersionCheck(true),
     reportStatistics(true),
     allowBetaUpgrades(false)
@@ -102,6 +106,10 @@ public:
     sg.addVarSetting(new IntSetting("app.upgradeCheckMethod", upgradeCheckMethod));
     sg.addVarSetting(new DateTimeSetting("app.upgradeCheckTime", upgradeCheckTime));
     sg.addVarSetting(new StringSetting("app.installationUuid", installationUuid));
+    sg.addVarSetting(new IntSetting("app.upgradeCallbacks", upgradeCallbacks));
+    sg.addVarSetting(new IntSetting("app.upgradeDeclines", upgradeDeclines));
+    sg.addVarSetting(new IntSetting("app.upgradeErrors", upgradeErrors));
+    sg.addVarSetting(new IntSetting("app.upgradeOffers", upgradeOffers));
 
     // Global preferences.
     sg.addVarSetting(new BoolSetting("app.startupVersionCheck", startupVersionCheck));
@@ -143,6 +151,10 @@ public:
   int   upgradeCheckMethod;
   QDateTime upgradeCheckTime;
   QString installationUuid;
+  int upgradeCallbacks;
+  int upgradeDeclines;
+  int upgradeErrors;
+  int upgradeOffers;
 
   // Global preferences.
   bool startupVersionCheck;
index b86782d1be8cdee64bdffa890fe31342ebe8f6ff..c525f350f8f44b25b0d19e7584b3ae67bb948df4 100644 (file)
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-// $Id: mainwindow.cpp,v 1.19 2010/04/11 22:38:06 robertl Exp $
+// $Id: mainwindow.cpp,v 1.20 2010/04/12 02:53:03 robertl Exp $
 //------------------------------------------------------------------------
 //
 //  Copyright (C) 2009  S. Khai Mong <khai@mangrai.com>.
@@ -190,11 +190,10 @@ MainWindow::MainWindow(QWidget* parent): QMainWindow(parent)
   //--- Restore from registry
   restoreSettings();
 
-  upgrade = new UpgradeCheck(parent, formatList);
+  upgrade = new UpgradeCheck(parent, formatList, bd);
   if (bd.startupVersionCheck) {
-    upgrade->checkForUpgrade(babelVersion, bd.upgradeCheckMethod, 
-                             bd.upgradeCheckTime, bd.installationUuid,
-                             bd.reportStatistics, allowBetaUpgrades());
+    upgrade->checkForUpgrade(babelVersion, bd.upgradeCheckTime, 
+                             allowBetaUpgrades());
   }
 }
 
@@ -1022,10 +1021,9 @@ void MainWindow::aboutActionX()
 //------------------------------------------------------------------------
 void MainWindow::upgradeCheckActionX()
 {
-    upgrade->checkForUpgrade(babelVersion, bd.upgradeCheckMethod, 
-                             QDateTime(QDate(2000, 1, 1), QTime(0, 0)), 
-                             bd.installationUuid,
-                             bd.reportStatistics, allowBetaUpgrades());
+    upgrade->checkForUpgrade(babelVersion, 
+                            QDateTime(QDate(2000, 1, 1), QTime(0, 0)), 
+                            allowBetaUpgrades());
 }
 
 //------------------------------------------------------------------------
index ca339aac9d714a5597dbed78d63eb0786bc40505..415fd7bcd24546a971c7888e509a9c0c6f8c1844 100644 (file)
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-// $Id: upgrade.cpp,v 1.24 2010/04/11 18:11:47 robertl Exp $
+// $Id: upgrade.cpp,v 1.25 2010/04/12 02:53:04 robertl Exp $
 /*
     Copyright (C) 2009, 2010  Robert Lipe, robertlipe@gpsbabel.org
 
@@ -20,8 +20,9 @@
  */
 
 
-#include "upgrade.h"
+#include "babeldata.h"
 #include "format.h"
+#include "upgrade.h"
 #include "../config.h"
 #include "../gbversion.h"
 
@@ -44,9 +45,13 @@ static const bool testing = true;
 static const bool testing = false;
 #endif
 
-UpgradeCheck::UpgradeCheck(QWidget *parent, QList<Format> &formatList) :
+UpgradeCheck::UpgradeCheck(QWidget *parent, QList<Format> &formatList,
+                           BabelData& bd) :
   QObject(parent),
-  http(0), formatList_(formatList), updateStatus_(updateUnknown)
+  http(0), 
+  formatList_(formatList), 
+  updateStatus_(updateUnknown),
+  bd_(bd)
 {
 }
 
@@ -113,16 +118,13 @@ QString UpgradeCheck::getOsVersion()
 }
 
 
-UpgradeCheck::updateStatus UpgradeCheck::checkForUpgrade(const QString &currentVersionIn,
-               int checkMethod,
+UpgradeCheck::updateStatus UpgradeCheck::checkForUpgrade(
+               const QString &currentVersionIn,
                const QDateTime &lastCheckTime,
-               const QString &installationUuid,
-               bool reportStatistics,
                bool allowBeta)
 {
   currentVersion = currentVersionIn;
   currentVersion.remove("GPSBabel Version ");
-  upgradeCheckMethod = checkMethod;
 
   QDateTime soonestCheckTime = lastCheckTime.addDays(1);
   if (!testing && QDateTime::currentDateTime() < soonestCheckTime) {
@@ -147,7 +149,7 @@ UpgradeCheck::updateStatus UpgradeCheck::checkForUpgrade(const QString &currentV
 
   QString args = "current_version=" + currentVersion;
   args += "&current_gui_version=" VERSION;
-  args += "&installation=" + installationUuid;
+  args += "&installation=" + bd_.installationUuid;
   args += "&os=" + getOsName();
 #if HAVE_UNAME
   struct utsname utsname;
@@ -160,6 +162,10 @@ UpgradeCheck::updateStatus UpgradeCheck::checkForUpgrade(const QString &currentV
   args += QString("&beta_ok=%1").arg(allowBeta); 
   args += "&lang=" + QLocale::languageToString(locale.language());
   args += "&last_checkin=" + lastCheckTime.toString(Qt::ISODate);
+  args += QString("&ugcb=%1").arg(bd_.upgradeCallbacks); 
+  args += QString("&ugdec=%1").arg(bd_.upgradeDeclines); 
+  args += QString("&ugoff=%1").arg(bd_.upgradeOffers); 
+  args += QString("&ugerr=%1").arg(bd_.upgradeErrors); 
 
   int j = 0;
 
@@ -172,7 +178,7 @@ UpgradeCheck::updateStatus UpgradeCheck::checkForUpgrade(const QString &currentV
     if (wc)
       args += QString("&uc%1=wr/%2/%3").arg(j++).arg(formatName).arg(wc);
   }
-  if (j && reportStatistics)
+  if (j && bd_.reportStatistics)
     args += QString("&uc=%1").arg(j);
 
   if (false && testing)
@@ -206,17 +212,33 @@ void UpgradeCheck::readResponseHeader(const QHttpResponseHeader &responseHeader)
 
 void UpgradeCheck::httpRequestFinished(int requestId, bool error)
 {
-  if (http == 0 || error)
+  bd_.upgradeCallbacks++;
+
+  if (http == 0 || error) {
+    bd_.upgradeErrors++;
     return;
+  }
 
-  if (requestId != httpRequestId)
+  // This is not an error state; it's just the internal state of Qt's network
+  // stack flailing around.
+  if (requestId != httpRequestId) {
     return;
+  }
 
   QString oresponse(http->readAll());
 
   QDomDocument document;
-  if (!document.setContent(oresponse))
+  int line = -1;
+  QString error_text;
+  // This shouldn't ever be seen by a user.  
+  if (!document.setContent(oresponse, &error_text, &line)) {
+    QMessageBox::critical(0, tr("Error"),
+           tr("Invalid return data at line %1: %2.")
+           .arg(line)
+          .arg( error_text));
+    bd_.upgradeErrors++;
     return;
+  }
 
   QString response;
   QString upgradeText;
@@ -248,6 +270,7 @@ void UpgradeCheck::httpRequestFinished(int requestId, bool error)
     upgradeText = upgrade.firstChildElement("overview").text();
     // String compare, not a numeric one.  Server will return "best first".
     if((updateVersion > currentVersion) && updateCandidate) {
+      bd_.upgradeOffers++;
       updateStatus_ = updateNeeded;
       response = tr("A new version of GPSBabel is available.<br />"
         "Your version is %1 <br />"
@@ -274,6 +297,7 @@ void UpgradeCheck::httpRequestFinished(int requestId, bool error)
         // downloadUrl.addQueryItem("os", getOsName());
         QDesktopServices::openUrl(downloadUrl);
       default: ;
+        bd_.upgradeDeclines++;
     }
   }
 
index 880380b3fd880140a5a677e0db04e5db695aa914..a782a84515a645511a68c1ab95f9622ab5c2c211 100644 (file)
@@ -19,6 +19,7 @@
 
  */
 
+#include "babeldata.h"
 #include "format.h"
 #include <QDialog>
 #include <QDateTime>
@@ -30,8 +31,7 @@ class QHttpResponseHeader;
 class UpgradeCheck : public QObject {
   Q_OBJECT
 public:
-  //UpgradeCheck(QWidget *parent = 0);
-  UpgradeCheck(QWidget *parent, QList<Format> &formatList);
+  UpgradeCheck(QWidget *parent, QList<Format> &formatList, BabelData& bd);
   ~UpgradeCheck();
 
   typedef enum {
@@ -39,14 +39,9 @@ public:
     updateCurrent,
     updateNeeded,
   } updateStatus;
-
   UpgradeCheck::updateStatus checkForUpgrade(const QString &babelVersion, 
-                                            int upgradeCheckMethod,
                                             const QDateTime &lastCheckTime,
-                                            const QString &installationUuid,
-                                             bool reportStatistics,
-                                             bool allowBeta
-                                             );
+                                             bool allowBeta);
   QDateTime getUpgradeWarningTime() {
     return upgradeWarningTime;
   }
@@ -70,6 +65,7 @@ protected:
   QString getOsVersion(void);
   QList<Format> &formatList_;
   updateStatus updateStatus_;
+  BabelData& bd_;
 
 private slots:
   void httpRequestFinished(int requestId, bool error);